<template>
  <div class="login">
    <ul>
      <li>用户名：<input type="text" v-model="user.name" /></li>
      <li>密码：<input type="password" v-model="user.pwd" /></li>
      <li><button @click="login">登陆</button></li>
    </ul>
  </div>
</template>

<script>
  export default {
    name: "login",
    data() {
      return {
        user: {
          name: "",
          pwd: ""
        }
      }
    },
    methods: {
      login() {
        var param  = JSON.stringify({
          name: this.user.name,
          pwd: this.user.pwd
        }),
        that = this,
        loginInfo;
        this.$http.post("/login.shtml", "param=" + param).then(data => {
          if (data.code == 200) {
            loginInfo = {"state": true, "time": (new Date().getTime() + 1000*60*60*12), "token": data.data.token}
            localStorage.setItem("loginInfo", JSON.stringify(loginInfo));
            that.$router.replace("/");
          }
        })
      }
    },
    beforeRouteEnter(to, from, next) {
      next(vm => {
      })
    },
    created() {
    }
  }
</script>